<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h2>获取当前时间</h2>
		<div id="myDiv">
			
		</div>
		<br>
		<button type="button" onclick="onAction();">获取时间</button>
		
		
		
		<h2>随机一句名言</h2>
		<div id="myDiv1">
			
		</div>
		<br>
		<button type="button" onclick="doAction1();">获取</button>
		
		
		<h2>获取诗词列表-包含作者信息</h2>
		<div id="myDiv2">
			
		</div>
		<button type="button" onclick="doAction2();">获取</button>
		
		<h2>获取诗词作者列表</h2>
		<div id="myDiv3">
			
		</div>
		<button type="button" onclick="doAction3();">获取</button>
		
		<h2>获取诗词列表</h2>
		<div id="myDiv4">
			
		</div>
		<button type="button" onclick="doAction4();">获取</button>
	</body>
	<script type="text/javascript">
		function onAction(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/getTime',true);
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.readyState == 4 && ajax.status == 200) {
					var obj = JSON.parse(ajax.responseText);
					var px = '日期：'+obj.result.date;
					px += '<br>'+'时间：'+obj.result.time;
					px += '<br>'+'星期：'+obj.result.weekday;
					px += '<br>'+'日期时间：'+obj.result.dateTime;
					console.log(obj)
					document.getElementById('myDiv').innerHTML = px;
					
				}
			}
			
		}
		
		function doAction1(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/sentences',true);
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var ajaxObj = JSON.parse(ajax.responseText);
					console.log(ajaxObj.result)
					document.getElementById('myDiv1').innerHTML = ajaxObj.result.name +' ———   '+ ajaxObj.result.from 
				}
			}
		}
		
		function doAction2(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetryFull?count=2&page=1',true);
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var ajaxObj = JSON.parse(ajax.responseText);
					var px = '';
					for (var i = 0; i < ajaxObj.result.length; i++) {
						px += ajaxObj.result[i].title+'<br>';
						px += ajaxObj.result[i].dynasty+'<br>';
						px += ajaxObj.result[i].writer+'<br>';
						px += ajaxObj.result[i].content+'<br>';
						px += ajaxObj.result[i].type+'<br>';
						px += ajaxObj.result[i].remark+'<br>';
						px += ajaxObj.result[i].appreciation+'<br>';
						px += ajaxObj.result[i].translation+'<br>';
						px += ajaxObj.result[i].simpleIntro+'<br>';
						px += ajaxObj.result[i].detailIntro+'<br>'+'<br>'+'<br>';
						
					}
					
					console.log(ajaxObj.result);
					console.log(ajaxObj.result[1]);
					document.getElementById('myDiv2').innerHTML = px;
				}
			}
		}
		function doAction3(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetryAuthor?count=2&page=1&name=李白',true);
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var ajaxObj = JSON.parse(ajax.responseText);
					console.log(ajaxObj.result)
					document.getElementById('myDiv3').innerHTML =  ajaxObj.result.name+'<br>'+ajaxObj.result.simpleIntro+'<br>'+ajaxObj.result.detailIntro
				}
			}
		}
		function doAction4(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetry?count=2&page=1',true);
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var ajaxObj = JSON.parse(ajax.responseText);
					var px = '';
					for (var i = 0; i < ajaxObj.result.length; i++) {
						px += ajaxObj.result[i].title+'<br>';
						px += ajaxObj.result[i].dynasty+'<br>';
						px += ajaxObj.result[i].writer+'<br>';
						px += ajaxObj.result[i].content+'<br>';
						px += ajaxObj.result[i].type+'<br>';
						px += ajaxObj.result[i].remark+'<br>';
						px += ajaxObj.result[i].appreciation+'<br>';
						px += ajaxObj.result[i].translation+'<br>'+'<br>'+'<br>';
						
					}
					console.log(ajaxObj.result)
					document.getElementById('myDiv4').innerHTML = px;
				}
			}
		}
	</script>
</html>
